/* StudentModel.java 
* Created on Dec 4, 2012 
*@Author: Mr.Viet 
*@Phone: 01683430426 
*@Email: phamvanvietcdhd@gmail.com
*/ 
package com.session5; 

import java.util.Vector;

import javax.swing.table.AbstractTableModel;

public class StudentModel extends AbstractTableModel {
	private String[] columns = {"Name","Address","Age"};
	private Vector<Student> vtrData;
	public StudentModel(){
		this.vtrData = new Vector<Student>();
		this.vtrData.addElement(new Student("Pham Van Viet", "Thanh Ha", 21));
		this.vtrData.addElement(new Student("Pham Thi Thu", "Ha Giang", 24));
		this.vtrData.addElement(new Student("Nguyen Van Minh", "Thanh Ha", 21));
		
	}

	public static void main(String[] args) {
	}
	@Override
	public String getColumnName(int c) {
		
		return columns[c];
	}

	@Override
	public int getColumnCount() {
		
		return this.columns.length;
	}

	@Override
	public int getRowCount() {
		
		return this.vtrData.size();
	}
	@Override
	public boolean isCellEditable(int r, int c) {
		if(c==0){
			return true;
		}
		return false;
	}
	@Override
	public Object getValueAt(int r, int c) {
		Student st = this.vtrData.get(r);
		switch(c){
			case 0:
				return st.getName();
			case 1:
				return st.getAddr();
			case 2:
				return st.getAge();
		}
		return null;
		
	}

}
